from fastmcp import FastMCP
import logging

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger(__name__)

mcp = FastMCP("calculator")

@mcp.tool()
def add(a: float, b: float) -> float:
    """加法运算"""
    return a + b

@mcp.tool()
def subtract(a: float, b: float) -> float:
    """减法运算"""
    return a - b

@mcp.tool()
def multiply(a: float, b: float) -> float:
    """乘法运算"""
    return a * b

@mcp.tool()
def divide(a: float, b: float) -> float:
    """除法运算"""
    if b == 0:
        raise ValueError("除数不能为零")
    return a / b

@mcp.resource("calculator://operations")
def operations() -> str:
    """获取可用运算列表"""
    return "加法 (add), 减法 (subtract), 乘法 (multiply), 除法 (divide)"

if __name__ == "__main__":
    mcp.run(transport="stdio")